import { userStore } from '@/stores'
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login', component: () => import('@/views/login/loginPage.vue')
    },
    {
      path: '/', component: () => import('@/views/layout/LayoutContainner.vue'),
      redirect: '/article/Manage',
      children: [
        {
          path: '/article/Manage', component: () =>
            import('@/views/article/ArticleManage.vue')

        },
        {
          path: '/article/Channel', component: () =>
            import('@/views/article/ArticleChannel.vue')

        }, {
          path: '/user/Avatar', component: () =>
            import('@/views/user/UserAvatar.vue')

        }, {
          path: '/user/Password', component: () =>
            import('@/views/user/UserPassword.vue')

        }, {
          path: '/user/Profile', component: () =>
            import('@/views/user/UserProfile.vue')

        }
      ]
    }

  ]
})

router.beforeEach((to, from) => {
  const userstore = new userStore()
  if (!userstore.token && to.path !== '/login') return '/login'
})
export default router
